package test;

import utils.sl651.*;

/**
 * SL651增强测试报文解析测试类
 * 用于测试新增的水文数据元素解析功能
 */
public class SL651EnhancedTestReportParsing {
    
    public static void main(String[] args) {
        System.out.println("=== SL651增强测试报文解析测试 ===\n");
        
        // 包含多种水文数据元素的测试报文
        String testMessageHex = "7E7E010012345678123430002B020003591011154947F1F1001234567848F0F05910111549201900000526190000053923000001273812115030190000122819000252919000182B19000072C19000052D19000062E1900004FF021B025574FF03082038121421038F77";
        
        System.out.println("测试报文内容: " + testMessageHex);
        System.out.println("报文长度: " + testMessageHex.length() + " 字符");
        System.out.println();
        
        try {
            // 使用HEX解码器直接解析
            SL651Message message = SL651HexDecoder.decode(testMessageHex);
            
            System.out.println("解析结果:");
            System.out.println("有效性: " + (message.isValid() ? "有效" : "无效"));
            if (!message.isValid()) {
                System.out.println("错误信息: " + message.getErrorMessage());
            } else {
                System.out.println("中心站地址: " + message.getCenterAddress());
                System.out.println("遥测站地址: " + message.getStationAddress());
                System.out.println("密码: " + message.getPassword());
                System.out.println("流水号: " + message.getSerialNumber());
                System.out.println("发报时间: " + message.getReportTime());
                System.out.println("CRC校验: " + (message.isCrcValid() ? "通过" : "失败"));
                
                System.out.println("\n数据元素:");
                message.getDataElements().forEach((key, value) -> 
                    System.out.println("  " + key + ": " + value)
                );
                
                System.out.println("\n摘要信息:");
                String summary = message.getDataElement("SUMMARY");
                if (summary != null) {
                    System.out.println(summary);
                }
                
                System.out.println("\n数据质量评估:");
                String qualityScore = message.getDataElement("DATA_QUALITY_SCORE");
                String qualityLevel = message.getDataElement("DATA_QUALITY_LEVEL");
                if (qualityScore != null && qualityLevel != null) {
                    System.out.println("  质量评分: " + qualityScore);
                    System.out.println("  质量等级: " + qualityLevel);
                }
            }
        } catch (Exception e) {
            System.err.println("解析异常: " + e.getMessage());
            e.printStackTrace();
        }
    }
}